package com.woniuxy.yoga.business.mq;



import com.woniuxy.yoga.business.client.AdminClient;
import com.woniuxy.yoga.business.dao.mapper.BusinessAccountMapper;
import com.woniuxy.yoga.business.dao.mapper.BusinessPaymentMapper;
import com.woniuxy.yoga.business.dao.mapper.StoreLoginLogMapper;
import com.woniuxy.yoga.business.dao.model.BusinessAccount;
import com.woniuxy.yoga.business.dao.model.BusinessPayment;
import com.woniuxy.yoga.business.dao.model.StoreLoginLog;
import com.woniuxy.yoga.business.model.exception.BusinessException;
import com.woniuxy.yoga.business.model.exception.BusinessExceptionCode;
import com.woniuxy.yoga.business.model.form.businesspayment.PaymentLogForm;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Component
public class CreateBusinessLogConsumer {


    @Autowired
    private StoreLoginLogMapper storeLoginLogMapper;

    @Autowired
    private BusinessAccountMapper businessAccountMapper;

    /**
     * 生成商家登录日志
     * @param storeLoginLog
     * @throws Exception
     */
    @RabbitListener(queuesToDeclare = {@Queue(name = "create-businessLoginLog")})
    @RabbitHandler
    public void consumer(StoreLoginLog storeLoginLog) throws Exception{
        BusinessAccount businessAccount = businessAccountMapper.selectById(storeLoginLog.getAccountId());
        if (businessAccount==null) {
            throw new BusinessException(BusinessExceptionCode.BUSINESS_EXCEPTION_CODE_ACCOUNT_NOTEXITS);
        }
        storeLoginLogMapper.insert(storeLoginLog);
    }
}
